<template>
  <div>
    <AplidForm v-model="formModel" @reset="onRest" @submit="onSubmit"
      v-bind="AppealHandleConfig(nowRowData.appealStatus)">
      <template v-slot:appeal_dataForm>
        <LogList apiIndex="view_dpAppealDetails_page" :tableName="nowRowData.tableName" :appealId="nowRowData.id"
          :batchNumber="nowRowData.id" @selection-change="handleSelection"></LogList>
      </template>
      <template v-slot:appeal_materialForm>
        <el-descriptions :title="`申诉数据批次号:${nowRowData.id}`" :column="1">
          <el-descriptions-item label="申诉人">
            {{ nowRowData.appealUserName }}
          </el-descriptions-item>

          <el-descriptions-item label="申诉时间">
            {{ nowRowData.appealTime }}
          </el-descriptions-item>
          <el-descriptions-item label="申诉内容">
            {{ nowRowData.appealContent }}
          </el-descriptions-item>
          <el-descriptions-item label="申诉人所属单位">
            {{ nowRowData.appealUnitName }}
          </el-descriptions-item>
          <el-descriptions-item label="申诉类型">
            {{ nowRowData.appealType == 0 ? '基础数据异常' : '业务数据异常' }}
          </el-descriptions-item>
        </el-descriptions>
      </template>
      <template v-slot:appeal_contentForm>
        <el-card style="width: 100%">
          <p>
            <span>情况说明:</span>
            <span>{{ nowRowData.appealDeclare }}</span>
          </p>
          <div>
            <p>证明材料</p>
            <FileList :item="{ label: '文件' }" :value="changeMaterials"></FileList>
          </div>
        </el-card>
      </template>
      <template v-slot:flagResultForm>
        <el-descriptions :column="1">
          <el-descriptions-item label="处理日期">
            {{ nowRowData.receiverTime }}
          </el-descriptions-item>
          <el-descriptions-item label="处理结果">
            <el-tag type="danger" effect="dark" v-if="nowRowData.appealResult == 0">驳回</el-tag>
            <el-tag type="success" effect="dark" v-if="nowRowData.appealResult == 1">通过</el-tag>
            <el-tag type="warning" effect="dark" v-if="nowRowData.appealResult == 2">部分通过</el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="驳回原因">
            {{ nowRowData.rejectReason }}
          </el-descriptions-item>
          <el-descriptions-item label="相关材料">
            <FileList :item="{ label: '文件' }" :value="nowRowData.receiverMaterial"></FileList>
          </el-descriptions-item>
        </el-descriptions>
      </template>
    </AplidForm>
  </div>
</template>

<script setup lang="ts">
import { getStore } from '@/utils/store'
import { AppealHandleConfig } from '../config'
import LogList from '@/views/datacenter/components/DataGather/LogList/index.vue'
import apiMod from '@/apiMod'
import FileList from '@/views/aplid/DetailPage/ContentListItem/FileList/index.vue'

type Props = {
  nowRowData?: any
}
const props = withDefaults(defineProps<Props>(), {})
const emit = defineEmits(['refresh'])
const formModel = ref({})
const changeMaterials = ref([])
let multipleSelection = []
changeMaterials.value = props.nowRowData.appealMaterial?.split(',') || []

const onSubmit = (form, done) => {
  const userInfo = getStore('userInfo') || {}
  apiMod
    .act_task_checkNew({
      ...form,
      user: {
        id: userInfo.id,
        username: userInfo.username,
      },
      successIds: multipleSelection.map((item) => item.id),
      processInstanceId: props.nowRowData.processInstanceId,
    })
    .then((res) => {
      emit('refresh')
      done()
    })
    .catch((err) => {
      done()
    })
}
const onRest = () => {
  emit('refresh')
}
const handleSelection = (arr) => {
  multipleSelection = arr
}
</script>

<style scoped></style>
